home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Acme Filters 2.3.2 folder.sit
/
Acme Filters 2.3.2 folder
/
Acme Filters 2.3.2
/
Acme Filters オ
/
Sources
/
TypeCreator.c
< prev
Wrap
Text File
|
1996-02-03
|
5KB
|
188 lines
/************ I N C L U D E F I L E S *******************************************************/
#include <stdio.h>
#include "Acme Filters.h"
#include "TypeCreator.h"
/**********************************************************************************************
* Function Name: TypeCreator
*
* Description: Set a file's type and creator codes.
*
* Parameters: iFile - file spec of a file.
* type - the selected file type.
* creator - the selected file creator.
*
* Return Value: None.
**********************************************************************************************/
void TypeCreator( FSSpec *iFile, OSType type, OSType creator )
{
FInfo iInfo;
gCancelReq |= Cancel();
ScrollIcon();
FSpGetFInfo( iFile, &iInfo );
iInfo.fdType = type;
iInfo.fdCreator = creator;
FSpSetFInfo( iFile, &iInfo );
TickleParentDir( iFile );
}
/**********************************************************************************************
* Function Name: PickTypeCreator
*
* Description: View or specify a file's type and creator codes.
*
* Parameters: file - the file.
* selType - the selected file type.
* selCrea - the selected file creator.
*
* Return Value: noErr if ok, error code otherwise.
**********************************************************************************************/
OSErr PickTypeCreator( FSSpec *file, OSType *selType, OSType *selCrea )
{
OSErr err = noErr;
DialogPtr picker;
WindowPtr saveMe;
Boolean done = false;
short item;
ModalFilterUPP filter = NewModalFilterProc( PickTypeCreatorDlgFltr );
FInfo info;
short iType;
Handle iHandle;
Rect iRect;
Str255 str;
OSType *cp = (OSType *)&str[1];
if ( picker = GetNewDialog( kTypeCreaDlog, nil, (WindowPtr)-1L ) )
{
// stuff the type and creator into the two TE fields
FSpGetFInfo( file, &info );
GetDItem( picker, kTEType, &iType, &iHandle, &iRect );
str[0] = 4;
*cp = info.fdType;
SetIText( iHandle, str );
GetDItem( picker, kTECreator, &iType, &iHandle, &iRect );
str[0] = 4;
*cp = info.fdCreator;
SetIText( iHandle, str );
SelIText( picker, kTEType, 0, 4 );
GetPort( &saveMe );
SetPort( picker );
ShowWindow( picker );
while ( !done )
{
ModalDialog( filter, &item );
switch( item )
{
case -1: // -1 + 1 = 0, ok
case -2: // -2 + 1 = -1, cancel
err = item + 1;
done = true;
break;
case kTEType:
case kTECreator:
GetDItem( picker, item, &iType, &iHandle, &iRect );
GetIText( iHandle, str );
if ( str[0] > 4 )
{
str[0] = 4;
SetIText( iHandle, str );
SysBeep( 1 );
}
break;
}
}
// retrieve the type and creator from the two TE fields
GetDItem( picker, kTEType, &iType, &iHandle, &iRect );
GetIText( iHandle, str );
*selType = *cp;
GetDItem( picker, kTECreator, &iType, &iHandle, &iRect );
GetIText( iHandle, str );
*selCrea = *cp;
SetPort( saveMe );
DisposDialog( picker );
}
return ( err );
}
/**********************************************************************************************
* Function Name: PickTypeCreatorDlgFltr
*
* Description: Handle mouse and keystrokes.
*
* Parameters: dialog - the dialog being filtered.
* event - the event record being processed.
* item - the item in which the event occured.
*
* Return Value: true - ModalDialog returns immediately and without handling the event.
* false - ModalDialog handles the event normally.
**********************************************************************************************/
pascal Boolean PickTypeCreatorDlgFltr( DialogPtr dialog, EventRecord *event, short *item )
{
char c;
Boolean result = false;
*item = 0;
if ( (event->what == keyDown) || (event->what == autoKey) )
{
c = event->message & charCodeMask;
if ( (c == kEnter) || (c == kReturn) )
{
if ( CodeOK( dialog, kTEType ) && CodeOK( dialog, kTECreator ) )
*item = -1;
result = true;
}
if ( (c == kEscape) || ((event->modifiers & cmdKey) && (c == kPeriod)) )
{
*item = -2;
result = true;
}
}
return ( result );
}
/**********************************************************************************************
* Function Name: CodeOK
*
* Description: Check if the code consists of exactly four characters.
*
* Parameters: dialog - a dialog.
* item - the text edit item to check.
*
* Return Value: true if ok, false otherwise.
**********************************************************************************************/
Boolean CodeOK( DialogPtr dialog, short item )
{
short iType;
Handle iHandle;
Rect iRect;
Str255 str;
GetDItem( dialog, item, &iType, &iHandle, &iRect );
GetIText( iHandle, str );
return ( str[0] == 4 );
}